package cn.com.pxto.client;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.params.DefaultHttpParams;
import org.apache.commons.httpclient.params.HttpParams;

public class FirstClient {
	private static  String URL="http://127.0.0.1/pxto/service";
	
	public static void main(String[] args) {
		
		HttpClient client=new HttpClient();
		
		PostMethod httppost = new PostMethod(URL);
		HttpParams params=new DefaultHttpParams();
		/*params.setParameter("cmdId", new Integer(1));
		client.getHostConfiguration().setParams(new HostParams(params));*/
		try {
			httppost.addParameter("cmdId", "1");
			client.executeMethod(httppost);
		} catch (HttpException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
/*		Object o1=client.getParams();
		Object o2=client.getState();
		Object o3=client.getHostConfiguration();
		Object o4=client.getHttpConnectionManager();*/
		
		Header[] header=httppost.getRequestHeaders();
		NameValuePair[] nameValuePair= httppost.getParameters();
		String str="";
		try {
			str=httppost.getResponseBodyAsString();
		} catch (IOException e) {
			e.printStackTrace();
		}
		System.out.println("str:"+str);
		Header[] header2=httppost.getResponseHeaders();
		RequestEntity reqEntity=httppost.getRequestEntity();
		String repstr="";
		try {
			byte[] bArray=httppost.getResponseBody();
			repstr=new String(bArray);
		} catch (IOException e) {
			e.printStackTrace();
		}
		System.out.println("repstr:"+repstr);
		System.out.println("success post client!");
		
		/*GetMethod httpget=new GetMethod(URL);
		
		try {
			client.executeMethod(httpget);
		} catch (HttpException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		*/
	}
}
